#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using System.Collections;
using Premiere.DTO;

#endregion

namespace PremiereMX
{
    public partial class PartFoundResultForm : Form
    {
        PartDTO m_partDTO;
        public delegate void EventLoad(PartDTO part, int row);
        EventLoad m_load;
        int m_activeRow = 0;

        public PartFoundResultForm(EventLoad loadevent, int activerow, IList result)
        {
            InitializeComponent();
            m_load = loadevent;
            m_activeRow = activerow;
            foreach (PartDTO part in result)
            {
                int t = dataGridView1.Rows.Add(part.Code, part.Name, part.PartGroup.Code);
                dataGridView1.Rows[t].Tag = part;
            }
        }
        private void dataGridView1_Click(object sender, EventArgs e)
        {
            if(dataGridView1.CurrentRow != null)
                return;
            m_partDTO = (PartDTO)dataGridView1.CurrentRow.Tag;
            m_load(m_partDTO, m_activeRow);
            this.Close();
        }

        private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '\r')
            {
                if (dataGridView1.CurrentRow == null)
                    return;
                m_partDTO = (PartDTO)dataGridView1.CurrentRow.Tag;
                m_load(m_partDTO, m_activeRow);
                this.Close();
            }
        }
    }
}